package it.trekker.upload.json;

import it.trekker.dao.Excursion;
import it.trekker.dao.ExcursionCoordinate;
import it.trekker.dao.GPSCoordinate;
import it.trekker.dao.Poi;
import it.trekker.dao.User;
import it.trekker.upload.UserUploaded;

import java.util.ArrayList;
import java.util.List;
import com.google.gson.annotations.SerializedName;


public class ExcursionAdapter {

	@SerializedName("user")
	private UserUploaded userUploaded;
	@SerializedName("excursion")
	private ExcursionUploaded excursionUploaded;
	@SerializedName("coordinates")
	private List<ExcursionCoordinateUploaded> coordinatesUploaded;
	@SerializedName("pois")
	private List<PoiUploaded> poisUploaded;

	public ExcursionAdapter() {
	}

	public UserUploaded getUserUploaded() {
		return userUploaded;
	}

	public void setUserUploaded(UserUploaded userUploaded) {
		this.userUploaded = userUploaded;
	}

	public ExcursionUploaded getExcursionUploaded() {
		return excursionUploaded;
	}

	public void setExcursionUploaded(ExcursionUploaded excursionUploaded) {
		this.excursionUploaded = excursionUploaded;
	}

	public List<ExcursionCoordinateUploaded> getCoordinatesUploaded() {
		return coordinatesUploaded;
	}

	public void setCoordinatesUploaded(
			List<ExcursionCoordinateUploaded> coordinatesUploaded) {
		this.coordinatesUploaded = coordinatesUploaded;
	}

	public List<PoiUploaded> getPoisUploaded() {
		return poisUploaded;
	}

	public void setPoisUploaded(List<PoiUploaded> poisUploaded) {
		this.poisUploaded = poisUploaded;
	}

	public Excursion getExcursion() {
		Excursion excursion = new Excursion();
		
		excursion.setName(excursionUploaded.getName());
		excursion.setDate(excursionUploaded.getDate());
		excursion.setDistance(excursionUploaded.getDistance());
		excursion.setTotAltitudeDifference(excursionUploaded.getTotAltitudeDifference());
		excursion.setTime(excursionUploaded.getTime());
		excursion.setMeanPace(excursionUploaded.getMeanPace());
		excursion.setSteps(excursionUploaded.getSteps());
		
		return excursion;
	}

	public List<ExcursionCoordinate> getCoordinates() {
		
		List<ExcursionCoordinate> list = new ArrayList<ExcursionCoordinate>();
		
		for(ExcursionCoordinateUploaded coordUploaded : coordinatesUploaded) {
			ExcursionCoordinate c = new ExcursionCoordinate();
			c.setTimestamp(coordUploaded.getTimestamp());
			GPSCoordinate gpsCoord = new GPSCoordinate();
			gpsCoord.setLatitude(coordUploaded.getCoordinate().getLatitude());
			gpsCoord.setLongitude(coordUploaded.getCoordinate().getLongitude());
			gpsCoord.setAltitude(coordUploaded.getCoordinate().getAltitude());
			c.setCoordinate(gpsCoord);
			
			list.add(c);
		}
		
		return list;
	}

	public List<Poi> getPois() {
		List<Poi> list = new ArrayList<Poi>();
		
		for(PoiUploaded poiUploaded : poisUploaded) {
			Poi p = new Poi();
			GPSCoordinate gpsCoord = new GPSCoordinate();
			gpsCoord.setLatitude(poiUploaded.getLocation().getLatitude());
			gpsCoord.setLongitude(poiUploaded.getLocation().getLongitude());
			gpsCoord.setAltitude(poiUploaded.getLocation().getAltitude());
			p.setLocation(gpsCoord);
			p.setFriendlyName(poiUploaded.getFriendlyName());
			
			list.add(p);
		}
		
		return list;
	}
	
	public User getUser() {
		User user = new User();
		
		user.setUsername(userUploaded.getUsername());
		
		return user;
	}
}
